package org.geektimes.projects.user.sql;

import org.geektimes.projects.user.domain.User;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class PrintDB {

    public static void main(String[] args) throws SQLException, IntrospectionException {

        String databaseURL = "jdbc:derby:/db/user-platform;create=true";
        Connection connection = DriverManager.getConnection(databaseURL);
        Statement statement = connection.createStatement();

        //执行查询语句DML
        statement.executeQuery("SELECT * from users");

        final BeanInfo userBeanInfo = Introspector.getBeanInfo(User.class, Object.class);

        for (PropertyDescriptor propertyDescriptor : userBeanInfo.getPropertyDescriptors()) {
            System.out.println("================");
            System.out.println(propertyDescriptor.getName());
            System.out.println(propertyDescriptor.getDisplayName());
            System.out.println(propertyDescriptor.getPropertyType());
            System.out.println(propertyDescriptor.getWriteMethod());
            System.out.println(propertyDescriptor.getReadMethod());
            System.out.println(propertyDescriptor.getPropertyEditorClass());
            System.out.println(propertyDescriptor.getShortDescription());
        }

    }

}
